home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / MacTutor Help Source / Code Resource Version / Pascal Example / utilities.p < prev   
Encoding:
Text File  |  1989-08-29  |  2.2 KB  |  80 lines  |  [TEXT/MPS ]

  1. {$S Utilities}
  2.  
  3. (* ------------------------------------------------- *)
  4. (*                  UTILITIES  UNIT                  *)
  5. (* ------------------------------------------------- *)
  6. (* Purpose: Provide 'nicety' functions for the About *)
  7. (*          credits box of this demo program.        *)
  8. (* ------------------------------------------------- *)
  9.  
  10. UNIT Utilities;
  11.  
  12. INTERFACE
  13.  
  14. USES
  15.   Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf;
  16.  
  17.   PROCEDURE BoldButton (DPtr         : DialogPtr;
  18.                           ItemNum     : integer);
  19.  
  20.   PROCEDURE CenterWindow(VAR theWindowPtr : DialogPtr;
  21.                                  bumpUp      : integer);
  22.                                 
  23. IMPLEMENTATION
  24.  
  25.   PROCEDURE BoldButton;
  26.  
  27.       VAR
  28.         iBox         : Rect;            
  29.         iType         : integer;        
  30.         iHandle     : Handle;        
  31.         oldPenState : PenState;        
  32.  
  33.       BEGIN { BoldButton }
  34.         SystemTask;
  35.         { New graf port is dialog box }
  36.         SetPort(DPtr);
  37.         GetPenState(oldPenState);
  38.         GetDItem(DPtr, itemNum, iType, iHandle, iBox);
  39.         InsetRect(iBox, -4, -4);
  40.         PenSize(3, 3);
  41.         FrameRoundRect(iBox, 16, 16);
  42.         SetPenState(oldPenState);
  43.       END; { BoldButton }
  44.  
  45.  
  46.   PROCEDURE CenterWindow;
  47.  
  48.     CONST
  49.       menuBar = 21;                            { The menu bar is 21 pixels high    }
  50.       
  51.     VAR
  52.       dialogHeight, dialogWidth: integer;    
  53.       centerTop, centerLeft: integer;        
  54.       pixels : integer;                     
  55.       temp : real;                            
  56.             
  57.     BEGIN { CenterWindow }
  58.       { Get the bounds of the dialog itself }
  59.       dialogHeight := theWindowPtr^.portRect.bottom - theWindowPtr^.portRect.top;
  60.       dialogWidth := theWindowPtr^.portRect.right - theWindowPtr^.portRect.left;
  61.       { Compute centering information }
  62.       centerTop := (screenbits.bounds.bottom + menuBar - dialogHeight) div 2;
  63.       centerLeft := (screenbits.bounds.right - dialogWidth) div 2;
  64.       pixels := 0;
  65.       { Did the programmer want this window raised slightly? }
  66.       IF (bumpUp > 0) AND (bumpUp < 80)  THEN
  67.         BEGIN
  68.           { Use a temporary variable, because trunc() has bug on intermediate exprs }
  69.           temp := centerTop * (bumpUp / 100.0);
  70.           pixels := trunc(temp);
  71.           centerTop := centerTop - pixels;
  72.         END;
  73.       { Make it visible & show it! }
  74.       MoveWindow(theWindowPtr, centerLeft, centerTop, true);
  75.       ShowWindow(theWindowPtr);
  76.     END;   { CenterWindow }
  77.     
  78. END.
  79.  
  80.